home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / NET / TCP.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  34KB  |  1,101 lines

  1. /*
  2.  * INET        An implementation of the TCP/IP protocol suite for the LINUX
  3.  *        operating system.  INET is implemented using the  BSD Socket
  4.  *        interface as the means of communication with the user level.
  5.  *
  6.  *        Definitions for the TCP module.
  7.  *
  8.  * Version:    @(#)tcp.h    1.0.5    05/23/93
  9.  *
  10.  * Authors:    Ross Biro, <bir7@leland.Stanford.Edu>
  11.  *        Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12.  *
  13.  *        This program is free software; you can redistribute it and/or
  14.  *        modify it under the terms of the GNU General Public License
  15.  *        as published by the Free Software Foundation; either version
  16.  *        2 of the License, or (at your option) any later version.
  17.  */
  18. #ifndef _TCP_H
  19. #define _TCP_H
  20.  
  21. #include <linux/config.h>
  22. #include <linux/tcp.h>
  23. #include <linux/slab.h>
  24. #include <net/checksum.h>
  25.  
  26. /* This is for all connections with a full identity, no wildcards.
  27.  * New scheme, half the table is for TIME_WAIT, the other half is
  28.  * for the rest.  I'll experiment with dynamic table growth later.
  29.  */
  30. #define TCP_HTABLE_SIZE        512
  31.  
  32. /* This is for listening sockets, thus all sockets which possess wildcards. */
  33. #define TCP_LHTABLE_SIZE    32    /* Yes, really, this is all you need. */
  34.  
  35. /* This is for all sockets, to keep track of the local port allocations. */
  36. #define TCP_BHTABLE_SIZE    512
  37.  
  38. /* tcp_ipv4.c: These need to be shared by v4 and v6 because the lookup
  39.  *             and hashing code needs to work with different AF's yet
  40.  *             the port space is shared.
  41.  */
  42. extern struct sock *tcp_established_hash[TCP_HTABLE_SIZE];
  43. extern struct sock *tcp_listening_hash[TCP_LHTABLE_SIZE];
  44.  
  45. /* There are a few simple rules, which allow for local port reuse by
  46.  * an application.  In essence:
  47.  *
  48.  *    1) Sockets bound to different interfaces may share a local port.
  49.  *       Failing that, goto test 2.
  50.  *    2) If all sockets have sk->reuse set, and none of them are in
  51.  *       TCP_LISTEN state, the port may be shared.
  52.  *       Failing that, goto test 3.
  53.  *    3) If all sockets are bound to a specific sk->rcv_saddr local
  54.  *       address, and none of them are the same, the port may be
  55.  *       shared.
  56.  *       Failing this, the port cannot be shared.
  57.  *
  58.  * The interesting point, is test #2.  This is what an FTP server does
  59.  * all day.  To optimize this case we use a specific flag bit defined
  60.  * below.  As we add sockets to a bind bucket list, we perform a
  61.  * check of: (newsk->reuse && (newsk->state != TCP_LISTEN))
  62.  * As long as all sockets added to a bind bucket pass this test,
  63.  * the flag bit will be set.
  64.  * The resulting situation is that tcp_v[46]_verify_bind() can just check
  65.  * for this flag bit, if it is set and the socket trying to bind has
  66.  * sk->reuse set, we don't even have to walk the owners list at all,
  67.  * we return that it is ok to bind this socket to the requested local port.
  68.  *
  69.  * Sounds like a lot of work, but it is worth it.  In a more naive
  70.  * implementation (ie. current FreeBSD etc.) the entire list of ports
  71.  * must be walked for each data port opened by an ftp server.  Needless
  72.  * to say, this does not scale at all.  With a couple thousand FTP
  73.  * users logged onto your box, isn't it nice to know that new data
  74.  * ports are created in O(1) time?  I thought so. ;-)    -DaveM
  75.  */
  76. struct tcp_bind_bucket {
  77.     unsigned short        port;
  78.     unsigned short        flags;
  79. #define TCPB_FLAG_LOCKED    0x0001
  80. #define TCPB_FLAG_FASTREUSE    0x0002
  81. #define TCPB_FLAG_GOODSOCKNUM    0x0004
  82.  
  83.     struct tcp_bind_bucket    *next;
  84.     struct sock        *owners;
  85.     struct tcp_bind_bucket    **pprev;
  86. };
  87.  
  88. extern struct tcp_bind_bucket *tcp_bound_hash[TCP_BHTABLE_SIZE];
  89. extern kmem_cache_t *tcp_bucket_cachep;
  90. extern struct tcp_bind_bucket *tcp_bucket_create(unsigned short snum);
  91. extern void tcp_bucket_unlock(struct sock *sk);
  92. extern int tcp_port_rover;
  93.  
  94. /* Level-1 socket-demux cache. */
  95. #define TCP_NUM_REGS        32
  96. extern struct sock *tcp_regs[TCP_NUM_REGS];
  97.  
  98. #define TCP_RHASH_FN(__fport) \
  99.     ((((__fport) >> 7) ^ (__fport)) & (TCP_NUM_REGS - 1))
  100. #define TCP_RHASH(__fport)    tcp_regs[TCP_RHASH_FN((__fport))]
  101. #define TCP_SK_RHASH_FN(__sock)    TCP_RHASH_FN((__sock)->dport)
  102. #define TCP_SK_RHASH(__sock)    tcp_regs[TCP_SK_RHASH_FN((__sock))]
  103.  
  104. static __inline__ void tcp_reg_zap(struct sock *sk)
  105. {
  106.     struct sock **rpp;
  107.  
  108.     rpp = &(TCP_SK_RHASH(sk));
  109.     if(*rpp == sk)
  110.         *rpp = NULL;
  111. }
  112.  
  113. /* These are AF independent. */
  114. static __inline__ int tcp_bhashfn(__u16 lport)
  115. {
  116.     return (lport & (TCP_BHTABLE_SIZE - 1));
  117. }
  118.  
  119. static __inline__ void tcp_sk_bindify(struct sock *sk)
  120. {
  121.     struct tcp_bind_bucket *tb;
  122.     unsigned short snum = sk->num;
  123.  
  124.     for(tb = tcp_bound_hash[tcp_bhashfn(snum)]; tb->port != snum; tb = tb->next)
  125.         ;
  126.     /* Update bucket flags. */
  127.     if(tb->owners == NULL) {
  128.         /* We're the first. */
  129.         if(sk->reuse && sk->state != TCP_LISTEN)
  130.             tb->flags = TCPB_FLAG_FASTREUSE;
  131.         else
  132.             tb->flags = 0;
  133.     } else {
  134.         if((tb->flags & TCPB_FLAG_FASTREUSE) &&
  135.            ((sk->reuse == 0) || (sk->state == TCP_LISTEN)))
  136.             tb->flags &= ~TCPB_FLAG_FASTREUSE;
  137.     }
  138.     if((sk->bind_next = tb->owners) != NULL)
  139.         tb->owners->bind_pprev = &sk->bind_next;
  140.     tb->owners = sk;
  141.     sk->bind_pprev = &tb->owners;
  142.     sk->prev = (struct sock *) tb;
  143. }
  144.  
  145. /* This is a TIME_WAIT bucket.  It works around the memory consumption
  146.  * problems of sockets in such a state on heavily loaded servers, but
  147.  * without violating the protocol specification.
  148.  */
  149. struct tcp_tw_bucket {
  150.     /* These _must_ match the beginning of struct sock precisely.
  151.      * XXX Yes I know this is gross, but I'd have to edit every single
  152.      * XXX networking file if I created a "struct sock_header". -DaveM
  153.      */
  154.     struct sock        *sklist_next;
  155.     struct sock        *sklist_prev;
  156.     struct sock        *bind_next;
  157.     struct sock        **bind_pprev;
  158.     __u32            daddr;
  159.     __u32            rcv_saddr;
  160.     __u16            dport;
  161.     unsigned short        num;
  162.     int            bound_dev_if;
  163.     struct sock        *next;
  164.     struct sock        **pprev;
  165.     unsigned char        state,
  166.                 zapped;
  167.     __u16            sport;
  168.     unsigned short        family;
  169.     unsigned char        reuse,
  170.                 nonagle;
  171.  
  172.     /* And these are ours. */
  173.     __u32            rcv_nxt;
  174.     struct tcp_func        *af_specific;
  175.     struct tcp_bind_bucket    *tb;
  176.     struct tcp_tw_bucket    *next_death;
  177.     int            death_slot;
  178. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  179.     struct in6_addr        v6_daddr;
  180.     struct in6_addr        v6_rcv_saddr;
  181. #endif
  182. };
  183.  
  184. extern kmem_cache_t *tcp_timewait_cachep;
  185.  
  186. /* Socket demux engine toys. */
  187. #ifdef __BIG_ENDIAN
  188. #define TCP_COMBINED_PORTS(__sport, __dport) \
  189.     (((__u32)(__sport)<<16) | (__u32)(__dport))
  190. #else /* __LITTLE_ENDIAN */
  191. #define TCP_COMBINED_PORTS(__sport, __dport) \
  192.     (((__u32)(__dport)<<16) | (__u32)(__sport))
  193. #endif
  194.  
  195. #if (BITS_PER_LONG == 64)
  196. #ifdef __BIG_ENDIAN
  197. #define TCP_V4_ADDR_COOKIE(__name, __saddr, __daddr) \
  198.     __u64 __name = (((__u64)(__saddr))<<32)|((__u64)(__daddr));
  199. #else /* __LITTLE_ENDIAN */
  200. #define TCP_V4_ADDR_COOKIE(__name, __saddr, __daddr) \
  201.     __u64 __name = (((__u64)(__daddr))<<32)|((__u64)(__saddr));
  202. #endif /* __BIG_ENDIAN */
  203. #define TCP_IPV4_MATCH(__sk, __cookie, __saddr, __daddr, __ports, __dif)\
  204.     (((*((__u64 *)&((__sk)->daddr)))== (__cookie))    &&        \
  205.      ((*((__u32 *)&((__sk)->dport)))== (__ports))   &&        \
  206.      (!((__sk)->bound_dev_if) || ((__sk)->bound_dev_if == (__dif))))
  207. #else /* 32-bit arch */
  208. #define TCP_V4_ADDR_COOKIE(__name, __saddr, __daddr)
  209. #define TCP_IPV4_MATCH(__sk, __cookie, __saddr, __daddr, __ports, __dif)\
  210.     (((__sk)->daddr            == (__saddr))    &&        \
  211.      ((__sk)->rcv_saddr        == (__daddr))    &&        \
  212.      ((*((__u32 *)&((__sk)->dport)))== (__ports))   &&        \
  213.      (!((__sk)->bound_dev_if) || ((__sk)->bound_dev_if == (__dif))))
  214. #endif /* 64-bit arch */
  215.  
  216. #define TCP_IPV6_MATCH(__sk, __saddr, __daddr, __ports, __dif)               \
  217.     (((*((__u32 *)&((__sk)->dport)))== (__ports))               && \
  218.      ((__sk)->family        == AF_INET6)                && \
  219.      !ipv6_addr_cmp(&(__sk)->net_pinfo.af_inet6.daddr, (__saddr))        && \
  220.      !ipv6_addr_cmp(&(__sk)->net_pinfo.af_inet6.rcv_saddr, (__daddr))    && \
  221.      (!((__sk)->bound_dev_if) || ((__sk)->bound_dev_if == (__dif))))
  222.  
  223. /* These can have wildcards, don't try too hard. */
  224. static __inline__ int tcp_lhashfn(unsigned short num)
  225. {
  226.     return num & (TCP_LHTABLE_SIZE - 1);
  227. }
  228.  
  229. static __inline__ int tcp_sk_listen_hashfn(struct sock *sk)
  230. {
  231.     return tcp_lhashfn(sk->num);
  232. }
  233.  
  234. /* Note, that it is > than ipv6 header */
  235. #define NETHDR_SIZE    (sizeof(struct iphdr) + 40)
  236.  
  237. /*
  238.  * 40 is maximal IP options size
  239.  * 20 is the maximum TCP options size we can currently construct on a SYN.
  240.  * 40 is the maximum possible TCP options size.
  241.  */
  242.  
  243. #define MAX_SYN_SIZE    (NETHDR_SIZE + sizeof(struct tcphdr) + 20 + MAX_HEADER + 15)
  244. #define MAX_FIN_SIZE    (NETHDR_SIZE + sizeof(struct tcphdr) + MAX_HEADER + 15)
  245. #define BASE_ACK_SIZE    (NETHDR_SIZE + MAX_HEADER + 15)
  246. #define MAX_ACK_SIZE    (NETHDR_SIZE + sizeof(struct tcphdr) + MAX_HEADER + 15)
  247. #define MAX_RESET_SIZE    (NETHDR_SIZE + sizeof(struct tcphdr) + MAX_HEADER + 15)
  248. #define MAX_TCPHEADER_SIZE (NETHDR_SIZE + sizeof(struct tcphdr) + 20 + MAX_HEADER + 15)
  249.  
  250. /* 
  251.  * Never offer a window over 32767 without using window scaling. Some
  252.  * poor stacks do signed 16bit maths! 
  253.  */
  254. #define MAX_WINDOW    32767    
  255. #define MIN_WINDOW    2048
  256. #define MAX_ACK_BACKLOG    2
  257. #define MAX_DELAY_ACK    2
  258. #define TCP_WINDOW_DIFF    2048
  259.  
  260. /* urg_data states */
  261. #define URG_VALID    0x0100
  262. #define URG_NOTYET    0x0200
  263. #define URG_READ    0x0400
  264.  
  265. #define TCP_RETR1    7    /*
  266.                  * This is how many retries it does before it
  267.                  * tries to figure out if the gateway is
  268.                  * down.
  269.                  */
  270.  
  271. #define TCP_RETR2    15    /*
  272.                  * This should take at least
  273.                  * 90 minutes to time out.
  274.                  */
  275.  
  276. #define TCP_TIMEOUT_LEN    (15*60*HZ) /* should be about 15 mins        */
  277. #define TCP_TIMEWAIT_LEN (60*HZ) /* how long to wait to successfully 
  278.                   * close the socket, about 60 seconds    */
  279. #define TCP_FIN_TIMEOUT (3*60*HZ) /* BSD style FIN_WAIT2 deadlock breaker */
  280.  
  281. #define TCP_ACK_TIME    (3*HZ)    /* time to delay before sending an ACK    */
  282. #define TCP_DONE_TIME    (5*HZ/2)/* maximum time to wait before actually
  283.                  * destroying a socket            */
  284. #define TCP_WRITE_TIME    (30*HZ)    /* initial time to wait for an ACK,
  285.                      * after last transmit            */
  286. #define TCP_TIMEOUT_INIT (3*HZ)    /* RFC 1122 initial timeout value    */
  287. #define TCP_SYN_RETRIES     10    /* number of times to retry opening a
  288.                  * connection     (TCP_RETR2-....)    */
  289. #define TCP_PROBEWAIT_LEN (1*HZ)/* time to wait between probes when
  290.                  * I've got something to write and
  291.                  * there is no window            */
  292. #define TCP_KEEPALIVE_TIME (180*60*HZ)        /* two hours */
  293. #define TCP_KEEPALIVE_PROBES    9        /* Max of 9 keepalive probes    */
  294. #define TCP_KEEPALIVE_PERIOD ((75*HZ)>>2)    /* period of keepalive check    */
  295.  
  296. #define TCP_SYNACK_PERIOD    (HZ/2) /* How often to run the synack slow timer */
  297. #define TCP_QUICK_TRIES        8  /* How often we try to retransmit, until
  298.                     * we tell the link layer that it is something
  299.                     * wrong (e.g. that it can expire redirects) */
  300.  
  301. #define TCP_BUCKETGC_PERIOD    (HZ)
  302.  
  303. /* TIME_WAIT reaping mechanism. */
  304. #define TCP_TWKILL_SLOTS    8    /* Please keep this a power of 2. */
  305. #define TCP_TWKILL_PERIOD    ((HZ*60)/TCP_TWKILL_SLOTS)
  306.  
  307. /*
  308.  *    TCP option
  309.  */
  310.  
  311. #define TCPOPT_NOP        1    /* Padding */
  312. #define TCPOPT_EOL        0    /* End of options */
  313. #define TCPOPT_MSS        2    /* Segment size negotiating */
  314. #define TCPOPT_WINDOW        3    /* Window scaling */
  315. #define TCPOPT_SACK_PERM        4       /* SACK Permitted */
  316. #define TCPOPT_SACK             5       /* SACK Block */
  317. #define TCPOPT_TIMESTAMP    8    /* Better RTT estimations/PAWS */
  318.  
  319. /*
  320.  *     TCP option lengths
  321.  */
  322.  
  323. #define TCPOLEN_MSS            4
  324. #define TCPOLEN_WINDOW         3
  325. #define TCPOLEN_SACK_PERM      2
  326. #define TCPOLEN_TIMESTAMP      10
  327.  
  328. /* But this is what stacks really send out. */
  329. #define TCPOLEN_TSTAMP_ALIGNED        12
  330. #define TCPOLEN_WSCALE_ALIGNED        4
  331. #define TCPOLEN_SACKPERM_ALIGNED    4
  332. #define TCPOLEN_SACK_BASE        2
  333. #define TCPOLEN_SACK_BASE_ALIGNED    4
  334. #define TCPOLEN_SACK_PERBLOCK        8
  335.  
  336. struct open_request;
  337.  
  338. struct or_calltable {
  339.     void (*rtx_syn_ack)    (struct sock *sk, struct open_request *req);
  340.     void (*destructor)    (struct open_request *req);
  341.     void (*send_reset)    (struct sk_buff *skb);
  342. };
  343.  
  344. struct tcp_v4_open_req {
  345.     __u32            loc_addr;
  346.     __u32            rmt_addr;
  347.     struct ip_options    *opt;
  348. };
  349.  
  350. #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
  351. struct tcp_v6_open_req {
  352.     struct in6_addr        loc_addr;
  353.     struct in6_addr        rmt_addr;
  354.     struct sk_buff        *pktopts;
  355.     int            iif;
  356. };
  357. #endif
  358.  
  359. /* this structure is too big */
  360. struct open_request {
  361.     struct open_request    *dl_next; /* Must be first member! */
  362.     __u32            rcv_isn;
  363.     __u32            snt_isn;
  364.     __u16            rmt_port;
  365.     __u16            mss;
  366.     __u8            retrans;
  367.     __u8            __pad;
  368.     unsigned snd_wscale : 4, 
  369.         rcv_wscale : 4, 
  370.         tstamp_ok : 1,
  371.         sack_ok : 1,
  372.         wscale_ok : 1;
  373.     /* The following two fields can be easily recomputed I think -AK */
  374.     __u32            window_clamp;    /* window clamp at creation time */
  375.     __u32            rcv_wnd;    /* rcv_wnd offered first time */
  376.     __u32            ts_recent;
  377.     unsigned long        expires;
  378.     struct or_calltable    *class;
  379.     struct sock        *sk;
  380.     union {
  381.         struct tcp_v4_open_req v4_req;
  382. #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
  383.         struct tcp_v6_open_req v6_req;
  384. #endif
  385.     } af;
  386. #ifdef CONFIG_IP_TRANSPARENT_PROXY
  387.     __u16            lcl_port; /* LVE */
  388. #endif
  389. };
  390.  
  391. /* SLAB cache for open requests. */
  392. extern kmem_cache_t *tcp_openreq_cachep;
  393.  
  394. #define tcp_openreq_alloc()    kmem_cache_alloc(tcp_openreq_cachep, SLAB_ATOMIC)
  395. #define tcp_openreq_free(req)    kmem_cache_free(tcp_openreq_cachep, req)
  396.  
  397. /*
  398.  *    Pointers to address related TCP functions
  399.  *    (i.e. things that depend on the address family)
  400.  *
  401.  *     BUGGG_FUTURE: all the idea behind this struct is wrong.
  402.  *    It mixes socket frontend with transport function.
  403.  *    With port sharing between IPv6/v4 it gives the only advantage,
  404.  *    only poor IPv6 needs to permanently recheck, that it
  405.  *    is still IPv6 8)8) It must be cleaned up as soon as possible.
  406.  *                        --ANK (980802)
  407.  */
  408.  
  409. struct tcp_func {
  410.     void            (*queue_xmit)        (struct sk_buff *skb);
  411.  
  412.     void            (*send_check)        (struct sock *sk,
  413.                              struct tcphdr *th,
  414.                              int len,
  415.                              struct sk_buff *skb);
  416.  
  417.     int            (*rebuild_header)    (struct sock *sk);
  418.  
  419.     int            (*conn_request)        (struct sock *sk,
  420.                              struct sk_buff *skb,
  421.                              __u32 isn);
  422.  
  423.     struct sock *        (*syn_recv_sock)    (struct sock *sk,
  424.                              struct sk_buff *skb,
  425.                              struct open_request *req,
  426.                              struct dst_entry *dst);
  427.     
  428.     struct sock *        (*get_sock)        (struct sk_buff *skb,
  429.                              struct tcphdr *th);
  430.  
  431.     __u16            net_header_len;
  432.  
  433.  
  434.  
  435.     int            (*setsockopt)        (struct sock *sk, 
  436.                              int level, 
  437.                              int optname, 
  438.                              char *optval, 
  439.                              int optlen);
  440.  
  441.     int            (*getsockopt)        (struct sock *sk, 
  442.                              int level, 
  443.                              int optname, 
  444.                              char *optval, 
  445.                              int *optlen);
  446.  
  447.  
  448.     void            (*addr2sockaddr)    (struct sock *sk,
  449.                              struct sockaddr *);
  450.  
  451.     int sockaddr_len;
  452. };
  453.  
  454. /*
  455.  * The next routines deal with comparing 32 bit unsigned ints
  456.  * and worry about wraparound (automatic with unsigned arithmetic).
  457.  */
  458.  
  459. extern __inline int before(__u32 seq1, __u32 seq2)
  460. {
  461.         return (__s32)(seq1-seq2) < 0;
  462. }
  463.  
  464. extern __inline int after(__u32 seq1, __u32 seq2)
  465. {
  466.     return (__s32)(seq2-seq1) < 0;
  467. }
  468.  
  469.  
  470. /* is s2<=s1<=s3 ? */
  471. extern __inline int between(__u32 seq1, __u32 seq2, __u32 seq3)
  472. {
  473.     return seq3 - seq2 >= seq1 - seq2;
  474. }
  475.  
  476.  
  477. extern struct proto tcp_prot;
  478. extern struct tcp_mib tcp_statistics;
  479.  
  480. extern unsigned short        tcp_good_socknum(void);
  481.  
  482. extern void            tcp_v4_err(struct sk_buff *skb,
  483.                        unsigned char *, int);
  484.  
  485. extern void            tcp_shutdown (struct sock *sk, int how);
  486.  
  487. extern int            tcp_v4_rcv(struct sk_buff *skb,
  488.                        unsigned short len);
  489.  
  490. extern int            tcp_do_sendmsg(struct sock *sk, struct msghdr *msg);
  491.  
  492. extern int            tcp_ioctl(struct sock *sk, 
  493.                       int cmd, 
  494.                       unsigned long arg);
  495.  
  496. extern int            tcp_rcv_state_process(struct sock *sk, 
  497.                               struct sk_buff *skb,
  498.                               struct tcphdr *th,
  499.                               unsigned len);
  500.  
  501. extern int            tcp_rcv_established(struct sock *sk, 
  502.                             struct sk_buff *skb,
  503.                             struct tcphdr *th, 
  504.                             unsigned len);
  505.  
  506. extern int            tcp_timewait_state_process(struct tcp_tw_bucket *tw,
  507.                                struct sk_buff *skb,
  508.                                struct tcphdr *th,
  509.                                unsigned len);
  510.  
  511. extern void            tcp_close(struct sock *sk, 
  512.                       long timeout);
  513. extern struct sock *        tcp_accept(struct sock *sk, int flags);
  514. extern unsigned int        tcp_poll(struct file * file, struct socket *sock, struct poll_table_struct *wait);
  515. extern void            tcp_write_space(struct sock *sk); 
  516.  
  517. extern int            tcp_getsockopt(struct sock *sk, int level, 
  518.                            int optname, char *optval, 
  519.                            int *optlen);
  520. extern int            tcp_setsockopt(struct sock *sk, int level, 
  521.                            int optname, char *optval, 
  522.                            int optlen);
  523. extern void            tcp_set_keepalive(struct sock *sk, int val);
  524. extern int            tcp_recvmsg(struct sock *sk, 
  525.                         struct msghdr *msg,
  526.                         int len, int nonblock, 
  527.                         int flags, int *addr_len);
  528.  
  529. extern void            tcp_parse_options(struct sock *sk, struct tcphdr *th,
  530.                           struct tcp_opt *tp, int no_fancy);
  531.  
  532. /*
  533.  *    TCP v4 functions exported for the inet6 API
  534.  */
  535.  
  536. extern int                   tcp_v4_rebuild_header(struct sock *sk);
  537.  
  538. extern int                   tcp_v4_build_header(struct sock *sk, 
  539.                             struct sk_buff *skb);
  540.  
  541. extern void                   tcp_v4_send_check(struct sock *sk, 
  542.                           struct tcphdr *th, int len, 
  543.                           struct sk_buff *skb);
  544.  
  545. extern int            tcp_v4_conn_request(struct sock *sk,
  546.                             struct sk_buff *skb,
  547.                             __u32 isn);
  548.  
  549. extern struct sock *        tcp_create_openreq_child(struct sock *sk,
  550.                              struct open_request *req,
  551.                              struct sk_buff *skb);
  552.  
  553. extern struct sock *        tcp_v4_syn_recv_sock(struct sock *sk,
  554.                              struct sk_buff *skb,
  555.                              struct open_request *req,
  556.                             struct dst_entry *dst);
  557.  
  558. extern int            tcp_v4_do_rcv(struct sock *sk,
  559.                           struct sk_buff *skb);
  560.  
  561. extern int            tcp_v4_connect(struct sock *sk,
  562.                            struct sockaddr *uaddr,
  563.                            int addr_len);
  564.  
  565. extern void            tcp_connect(struct sock *sk,
  566.                         struct sk_buff *skb,
  567.                         int est_mss);
  568.  
  569. extern struct sk_buff *        tcp_make_synack(struct sock *sk,
  570.                         struct dst_entry *dst,
  571.                         struct open_request *req,
  572.                         int mss);
  573.  
  574.  
  575. /* From syncookies.c */
  576. extern struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 
  577.                     struct ip_options *opt);
  578. extern __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, 
  579.                      __u16 *mss);
  580.  
  581. /* tcp_output.c */
  582.  
  583. extern void tcp_read_wakeup(struct sock *);
  584. extern void tcp_write_xmit(struct sock *);
  585. extern void tcp_time_wait(struct sock *);
  586. extern int tcp_retransmit_skb(struct sock *, struct sk_buff *);
  587. extern void tcp_fack_retransmit(struct sock *);
  588. extern void tcp_xmit_retransmit_queue(struct sock *);
  589. extern void tcp_simple_retransmit(struct sock *);
  590.  
  591. extern void tcp_send_probe0(struct sock *);
  592. extern void tcp_send_partial(struct sock *);
  593. extern void tcp_write_wakeup(struct sock *);
  594. extern void tcp_send_fin(struct sock *sk);
  595. extern void tcp_send_active_reset(struct sock *sk);
  596. extern int  tcp_send_synack(struct sock *);
  597. extern void tcp_transmit_skb(struct sock *, struct sk_buff *);
  598. extern void tcp_send_skb(struct sock *, struct sk_buff *, int force_queue);
  599. extern void tcp_send_ack(struct sock *sk);
  600. extern void tcp_send_delayed_ack(struct tcp_opt *tp, int max_timeout);
  601.  
  602. /* CONFIG_IP_TRANSPARENT_PROXY */
  603. extern int tcp_chkaddr(struct sk_buff *);
  604.  
  605. /* tcp_timer.c */
  606. #define     tcp_reset_msl_timer(x,y,z)    net_reset_timer(x,y,z)
  607. extern void tcp_reset_xmit_timer(struct sock *, int, unsigned long);
  608. extern void tcp_init_xmit_timers(struct sock *);
  609. extern void tcp_clear_xmit_timers(struct sock *);
  610.  
  611. extern void tcp_retransmit_timer(unsigned long);
  612. extern void tcp_delack_timer(unsigned long);
  613. extern void tcp_probe_timer(unsigned long);
  614.  
  615. extern struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, 
  616.                   struct open_request *req);
  617.  
  618. /*
  619.  *    TCP slow timer
  620.  */
  621. extern struct timer_list    tcp_slow_timer;
  622.  
  623. struct tcp_sl_timer {
  624.     atomic_t    count;
  625.     unsigned long    period;
  626.     unsigned long    last;
  627.     void (*handler)    (unsigned long);
  628. };
  629.  
  630. #define TCP_SLT_SYNACK        0
  631. #define TCP_SLT_KEEPALIVE    1
  632. #define TCP_SLT_TWKILL        2
  633. #define TCP_SLT_BUCKETGC    3
  634. #define TCP_SLT_MAX        4
  635.  
  636. extern struct tcp_sl_timer tcp_slt_array[TCP_SLT_MAX];
  637.  
  638. extern int tcp_sync_mss(struct sock *sk, u32 pmtu);
  639.  
  640. /* Compute the current effective MSS, taking SACKs and IP options,
  641.  * and even PMTU discovery events into account.
  642.  */
  643.  
  644. static __inline__ unsigned int tcp_current_mss(struct sock *sk)
  645. {
  646.     struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
  647.     struct dst_entry *dst = sk->dst_cache;
  648.     int mss_now = tp->mss_cache; 
  649.  
  650.     if (dst && dst->pmtu != tp->pmtu_cookie)
  651.         mss_now = tcp_sync_mss(sk, dst->pmtu);
  652.  
  653.     if(tp->sack_ok && tp->num_sacks)
  654.         mss_now -= (TCPOLEN_SACK_BASE_ALIGNED +
  655.                 (tp->num_sacks * TCPOLEN_SACK_PERBLOCK));
  656.     return mss_now > 8 ? mss_now : 8;
  657. }
  658.  
  659. /* Compute the actual receive window we are currently advertising.
  660.  * Rcv_nxt can be after the window if our peer push more data
  661.  * than the offered window.
  662.  */
  663. static __inline__ u32 tcp_receive_window(struct tcp_opt *tp)
  664. {
  665.     s32 win = tp->rcv_wup + tp->rcv_wnd - tp->rcv_nxt;
  666.  
  667.     if (win < 0)
  668.         win = 0;
  669.     return (u32) win;
  670. }
  671.  
  672. /* Choose a new window, without checks for shrinking, and without
  673.  * scaling applied to the result.  The caller does these things
  674.  * if necessary.  This is a "raw" window selection.
  675.  */
  676. extern u32    __tcp_select_window(struct sock *sk);
  677.  
  678. /* Chose a new window to advertise, update state in tcp_opt for the
  679.  * socket, and return result with RFC1323 scaling applied.  The return
  680.  * value can be stuffed directly into th->window for an outgoing
  681.  * frame.
  682.  */
  683. extern __inline__ u16 tcp_select_window(struct sock *sk)
  684. {
  685.     struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
  686.     u32 cur_win = tcp_receive_window(tp);
  687.     u32 new_win = __tcp_select_window(sk);
  688.  
  689.     /* Never shrink the offered window */
  690.     if(new_win < cur_win) {
  691.         /* Danger Will Robinson!
  692.          * Don't update rcv_wup/rcv_wnd here or else
  693.          * we will not be able to advertise a zero
  694.          * window in time.  --DaveM
  695.          */
  696.         new_win = cur_win;
  697.     } else {
  698.         tp->rcv_wnd = new_win;
  699.         tp->rcv_wup = tp->rcv_nxt;
  700.     }
  701.  
  702.     /* RFC1323 scaling applied */
  703.     return new_win >> tp->rcv_wscale;
  704. }
  705.  
  706. /* See if we can advertise non-zero, and if so how much we
  707.  * can increase our advertisement.  If it becomes more than
  708.  * twice what we are talking about right now, return true.
  709.  */
  710. extern __inline__ int tcp_raise_window(struct sock *sk)
  711. {
  712.     struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
  713.     u32 cur_win = tcp_receive_window(tp);
  714.     u32 new_win = __tcp_select_window(sk);
  715.  
  716.     return (new_win && (new_win > (cur_win << 1)));
  717. }
  718.  
  719. /* This is what the send packet queueing engine uses to pass
  720.  * TCP per-packet control information to the transmission
  721.  * code.  We also store the host-order sequence numbers in
  722.  * here too.  This is 36 bytes on 32-bit architectures,
  723.  * 40 bytes on 64-bit machines, if this grows please adjust
  724.  * skbuff.h:skbuff->cb[xxx] size appropriately.
  725.  */
  726. struct tcp_skb_cb {
  727.     union {
  728.         struct inet_skb_parm    h4;
  729. #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
  730.         struct inet6_skb_parm    h6;
  731. #endif
  732.     } header;    /* For incoming frames        */
  733.     __u32        seq;        /* Starting sequence number    */
  734.     __u32        end_seq;    /* SEQ + FIN + SYN + datalen    */
  735.     unsigned long    when;        /* used to compute rtt's    */
  736.     __u8        flags;        /* TCP header flags.        */
  737.  
  738.     /* NOTE: These must match up to the flags byte in a
  739.      *       real TCP header.
  740.      */
  741. #define TCPCB_FLAG_FIN        0x01
  742. #define TCPCB_FLAG_SYN        0x02
  743. #define TCPCB_FLAG_RST        0x04
  744. #define TCPCB_FLAG_PSH        0x08
  745. #define TCPCB_FLAG_ACK        0x10
  746. #define TCPCB_FLAG_URG        0x20
  747.  
  748.     __u8        sacked;        /* State flags for SACK/FACK.    */
  749. #define TCPCB_SACKED_ACKED    0x01    /* SKB ACK'd by a SACK block    */
  750. #define TCPCB_SACKED_RETRANS    0x02    /* SKB retransmitted        */
  751.  
  752.     __u16        urg_ptr;    /* Valid w/URG flags is set.    */
  753.     __u32        ack_seq;    /* Sequence number ACK'd    */
  754. };
  755.  
  756. #define TCP_SKB_CB(__skb)    ((struct tcp_skb_cb *)&((__skb)->cb[0]))
  757.  
  758. /* This determines how many packets are "in the network" to the best
  759.  * of our knowledge.  In many cases it is conservative, but where
  760.  * detailed information is available from the receiver (via SACK
  761.  * blocks etc.) we can make more aggressive calculations.
  762.  *
  763.  * Use this for decisions involving congestion control, use just
  764.  * tp->packets_out to determine if the send queue is empty or not.
  765.  *
  766.  * Read this equation as:
  767.  *
  768.  *    "Packets sent once on transmission queue" MINUS
  769.  *    "Packets acknowledged by FACK information" PLUS
  770.  *    "Packets fast retransmitted"
  771.  */
  772. static __inline__ int tcp_packets_in_flight(struct tcp_opt *tp)
  773. {
  774.     return tp->packets_out - tp->fackets_out + tp->retrans_out;
  775. }
  776.  
  777. /* This checks if the data bearing packet SKB (usually tp->send_head)
  778.  * should be put on the wire right now.
  779.  */
  780. static __inline__ int tcp_snd_test(struct sock *sk, struct sk_buff *skb)
  781. {
  782.     struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
  783.     int nagle_check = 1;
  784.  
  785.     /*    RFC 1122 - section 4.2.3.4
  786.      *
  787.      *    We must queue if
  788.      *
  789.      *    a) The right edge of this frame exceeds the window
  790.      *    b) There are packets in flight and we have a small segment
  791.      *       [SWS avoidance and Nagle algorithm]
  792.      *       (part of SWS is done on packetization)
  793.      *    c) We are retransmiting [Nagle]
  794.      *    d) We have too many packets 'in flight'
  795.      *
  796.      *     Don't use the nagle rule for urgent data.
  797.      */
  798.     if ((sk->nonagle == 2 && (skb->len < tp->mss_cache)) ||
  799.         (!sk->nonagle &&
  800.          skb->len < (tp->mss_cache >> 1) &&
  801.          tp->packets_out &&
  802.          !(TCP_SKB_CB(skb)->flags & TCPCB_FLAG_URG)))
  803.         nagle_check = 0;
  804.  
  805.     return (nagle_check &&
  806.         (tcp_packets_in_flight(tp) < tp->snd_cwnd) &&
  807.         !after(TCP_SKB_CB(skb)->end_seq, tp->snd_una + tp->snd_wnd) &&
  808.         tp->retransmits == 0);
  809. }
  810.  
  811. /* Push out any pending frames which were held back due to
  812.  * TCP_CORK or attempt at coalescing tiny packets.
  813.  * The socket must be locked by the caller.
  814.  */
  815. static __inline__ void tcp_push_pending_frames(struct sock *sk, struct tcp_opt *tp)
  816. {
  817.     if(tp->send_head) {
  818.         if(tcp_snd_test(sk, tp->send_head))
  819.             tcp_write_xmit(sk);
  820.         else if(tp->packets_out == 0 && !tp->pending) {
  821.             /* We held off on this in tcp_send_skb() */
  822.             tp->pending = TIME_PROBE0;
  823.             tcp_reset_xmit_timer(sk, TIME_PROBE0, tp->rto);
  824.         }
  825.     }
  826. }
  827.  
  828. /* This tells the input processing path that an ACK should go out
  829.  * right now.
  830.  */
  831. #define tcp_enter_quickack_mode(__tp)    ((__tp)->ato |= (1<<31))
  832. #define tcp_exit_quickack_mode(__tp)    ((__tp)->ato &= ~(1<<31))
  833. #define tcp_in_quickack_mode(__tp)    (((__tp)->ato & (1 << 31)) != 0)
  834.  
  835. /*
  836.  * List all states of a TCP socket that can be viewed as a "connected"
  837.  * state.  This now includes TCP_SYN_RECV, although I am not yet fully
  838.  * convinced that this is the solution for the 'getpeername(2)'
  839.  * problem. Thanks to Stephen A. Wood <saw@cebaf.gov>  -FvK
  840.  */
  841.  
  842. extern __inline const int tcp_connected(const int state)
  843. {
  844.     return ((1 << state) &
  845.                (TCPF_ESTABLISHED|TCPF_CLOSE_WAIT|TCPF_FIN_WAIT1|
  846.          TCPF_FIN_WAIT2|TCPF_SYN_RECV));
  847. }
  848.  
  849. /*
  850.  * Calculate(/check) TCP checksum
  851.  */
  852. static __inline__ u16 tcp_v4_check(struct tcphdr *th, int len,
  853.                    unsigned long saddr, unsigned long daddr, 
  854.                    unsigned long base)
  855. {
  856.     return csum_tcpudp_magic(saddr,daddr,len,IPPROTO_TCP,base);
  857. }
  858.  
  859. #undef STATE_TRACE
  860.  
  861. #ifdef STATE_TRACE
  862. static char *statename[]={
  863.     "Unused","Established","Syn Sent","Syn Recv",
  864.     "Fin Wait 1","Fin Wait 2","Time Wait", "Close",
  865.     "Close Wait","Last ACK","Listen","Closing"
  866. };
  867. #endif
  868.  
  869. static __inline__ void tcp_set_state(struct sock *sk, int state)
  870. {
  871.     int oldstate = sk->state;
  872.  
  873.     sk->state = state;
  874.  
  875. #ifdef STATE_TRACE
  876.     SOCK_DEBUG(sk, "TCP sk=%p, State %s -> %s\n",sk, statename[oldstate],statename[state]);
  877. #endif    
  878.  
  879.     switch (state) {
  880.     case TCP_ESTABLISHED:
  881.         if (oldstate != TCP_ESTABLISHED)
  882.             tcp_statistics.TcpCurrEstab++;
  883.         break;
  884.  
  885.     case TCP_CLOSE:
  886.         {
  887.         struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
  888.         /* Should be about 2 rtt's */
  889.         net_reset_timer(sk, TIME_DONE, min(tp->srtt * 2, TCP_DONE_TIME));
  890.         sk->prot->unhash(sk);
  891.         /* fall through */
  892.         }
  893.     default:
  894.         if (oldstate==TCP_ESTABLISHED)
  895.             tcp_statistics.TcpCurrEstab--;
  896.     }
  897. }
  898.  
  899. static __inline__ void tcp_build_and_update_options(__u32 *ptr, struct tcp_opt *tp, __u32 tstamp)
  900. {
  901.     if (tp->tstamp_ok) {
  902.         *ptr++ = __constant_htonl((TCPOPT_NOP << 24) |
  903.                       (TCPOPT_NOP << 16) |
  904.                       (TCPOPT_TIMESTAMP << 8) |
  905.                       TCPOLEN_TIMESTAMP);
  906.         *ptr++ = htonl(tstamp);
  907.         *ptr++ = htonl(tp->ts_recent);
  908.     }
  909.     if(tp->sack_ok && tp->num_sacks) {
  910.         int this_sack;
  911.  
  912.         *ptr++ = __constant_htonl((TCPOPT_NOP << 24) |
  913.                       (TCPOPT_NOP << 16) |
  914.                       (TCPOPT_SACK << 8) |
  915.                       (TCPOLEN_SACK_BASE +
  916.                        (tp->num_sacks * TCPOLEN_SACK_PERBLOCK)));
  917.         for(this_sack = 0; this_sack < tp->num_sacks; this_sack++) {
  918.             *ptr++ = htonl(tp->selective_acks[this_sack].start_seq);
  919.             *ptr++ = htonl(tp->selective_acks[this_sack].end_seq);
  920.         }
  921.     }
  922. }
  923.  
  924. /* Construct a tcp options header for a SYN or SYN_ACK packet.
  925.  * If this is every changed make sure to change the definition of
  926.  * MAX_SYN_SIZE to match the new maximum number of options that you
  927.  * can generate.
  928.  */
  929. extern __inline__ void tcp_syn_build_options(__u32 *ptr, int mss, int ts, int sack,
  930.                          int offer_wscale, int wscale, __u32 tstamp, __u32 ts_recent)
  931. {
  932.     /* We always get an MSS option.
  933.      * The option bytes which will be seen in normal data
  934.      * packets should timestamps be used, must be in the MSS
  935.      * advertised.  But we subtract them from sk->mss so
  936.      * that calculations in tcp_sendmsg are simpler etc.
  937.      * So account for this fact here if necessary.  If we
  938.      * don't do this correctly, as a receiver we won't
  939.      * recognize data packets as being full sized when we
  940.      * should, and thus we won't abide by the delayed ACK
  941.      * rules correctly.
  942.      * SACKs don't matter, we never delay an ACK when we
  943.      * have any of those going out.
  944.      */
  945.     *ptr++ = htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) | mss);
  946.     if (ts) {
  947.         if(sack)
  948.             *ptr++ = __constant_htonl((TCPOPT_SACK_PERM << 24) | (TCPOLEN_SACK_PERM << 16) |
  949.                           (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP);
  950.         else
  951.             *ptr++ = __constant_htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
  952.                           (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP);
  953.         *ptr++ = htonl(tstamp);        /* TSVAL */
  954.         *ptr++ = htonl(ts_recent);    /* TSECR */
  955.     } else if(sack)
  956.         *ptr++ = __constant_htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
  957.                       (TCPOPT_SACK_PERM << 8) | TCPOLEN_SACK_PERM);
  958.     if (offer_wscale)
  959.         *ptr++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_WINDOW << 16) | (TCPOLEN_WINDOW << 8) | (wscale));
  960. }
  961.  
  962. /* Determine a window scaling and initial window to offer.
  963.  * Based on the assumption that the given amount of space
  964.  * will be offered. Store the results in the tp structure.
  965.  * NOTE: for smooth operation initial space offering should
  966.  * be a multiple of mss if possible. We assume here that mss >= 1.
  967.  * This MUST be enforced by all callers.
  968.  */
  969. extern __inline__ void tcp_select_initial_window(__u32 space, __u16 mss,
  970.     __u32 *rcv_wnd,
  971.     __u32 *window_clamp,
  972.     int wscale_ok,
  973.     __u8 *rcv_wscale)
  974. {
  975.     /* If no clamp set the clamp to the max possible scaled window */
  976.     if (*window_clamp == 0)
  977.         (*window_clamp) = (65535<<14);
  978.     space = min(*window_clamp,space);
  979.  
  980.     /* Quantize space offering to a multiple of mss if possible. */
  981.     if (space > mss)
  982.         space = (space/mss)*mss;
  983.  
  984.     /* NOTE: offering an initial window larger than 32767
  985.      * will break some buggy TCP stacks. We try to be nice.
  986.      * If we are not window scaling, then this truncates
  987.      * our initial window offering to 32k. There should also
  988.      * be a sysctl option to stop being nice.
  989.      */
  990.     (*rcv_wnd) = min(space, MAX_WINDOW);
  991.     (*rcv_wscale) = 0;
  992.     if (wscale_ok) {
  993.         /* See RFC1323 for an explanation of the limit to 14 */
  994.         while (space > 65535 && (*rcv_wscale) < 14) {
  995.             space >>= 1;
  996.             (*rcv_wscale)++;
  997.         }
  998.     }
  999.     /* Set the clamp no higher than max representable value */
  1000.     (*window_clamp) = min(65535<<(*rcv_wscale),*window_clamp);
  1001. }
  1002.  
  1003. extern __inline__ void tcp_synq_unlink(struct tcp_opt *tp, struct open_request *req, struct open_request *prev)
  1004. {
  1005.     if(!req->dl_next)
  1006.         tp->syn_wait_last = (struct open_request **)prev;
  1007.     prev->dl_next = req->dl_next;
  1008. }
  1009.  
  1010. extern __inline__ void tcp_synq_queue(struct tcp_opt *tp, struct open_request *req)
  1011.     req->dl_next = NULL;
  1012.     *tp->syn_wait_last = req; 
  1013.     tp->syn_wait_last = &req->dl_next;
  1014. }
  1015.  
  1016. extern __inline__ void tcp_synq_init(struct tcp_opt *tp)
  1017. {
  1018.     tp->syn_wait_queue = NULL;
  1019.     tp->syn_wait_last = &tp->syn_wait_queue;
  1020. }
  1021.  
  1022. extern void __tcp_inc_slow_timer(struct tcp_sl_timer *slt);
  1023. extern __inline__ void tcp_inc_slow_timer(int timer)
  1024. {
  1025.     struct tcp_sl_timer *slt = &tcp_slt_array[timer];
  1026.     
  1027.     if (atomic_read(&slt->count) == 0)
  1028.     {
  1029.         __tcp_inc_slow_timer(slt);
  1030.     }
  1031.  
  1032.     atomic_inc(&slt->count);
  1033. }
  1034.  
  1035. extern __inline__ void tcp_dec_slow_timer(int timer)
  1036. {
  1037.     struct tcp_sl_timer *slt = &tcp_slt_array[timer];
  1038.  
  1039.     atomic_dec(&slt->count);
  1040. }
  1041.  
  1042. /* This needs to use a slow timer, so it is here. */
  1043. static __inline__ void tcp_sk_unbindify(struct sock *sk)
  1044. {
  1045.     struct tcp_bind_bucket *tb = (struct tcp_bind_bucket *) sk->prev;
  1046.     if(sk->bind_next)
  1047.         sk->bind_next->bind_pprev = sk->bind_pprev;
  1048.     *sk->bind_pprev = sk->bind_next;
  1049.     if(tb->owners == NULL)
  1050.         tcp_inc_slow_timer(TCP_SLT_BUCKETGC);
  1051. }
  1052.  
  1053. extern const char timer_bug_msg[];
  1054.  
  1055. static inline void tcp_clear_xmit_timer(struct sock *sk, int what)
  1056. {
  1057.     struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
  1058.     struct timer_list *timer;
  1059.     
  1060.     switch (what) {
  1061.     case TIME_RETRANS:
  1062.         timer = &tp->retransmit_timer;
  1063.         break;
  1064.     case TIME_DACK:
  1065.         timer = &tp->delack_timer;
  1066.         break;
  1067.     case TIME_PROBE0:
  1068.         timer = &tp->probe_timer;
  1069.         break;    
  1070.     default:
  1071.         printk(timer_bug_msg);
  1072.         return;
  1073.     };
  1074.     if(timer->prev != NULL)
  1075.         del_timer(timer);
  1076. }
  1077.  
  1078. static inline int tcp_timer_is_set(struct sock *sk, int what)
  1079. {
  1080.     struct tcp_opt *tp = &sk->tp_pinfo.af_tcp;
  1081.  
  1082.     switch (what) {
  1083.     case TIME_RETRANS:
  1084.         return tp->retransmit_timer.prev != NULL;
  1085.         break;
  1086.     case TIME_DACK:
  1087.         return tp->delack_timer.prev != NULL;
  1088.         break;
  1089.     case TIME_PROBE0:
  1090.         return tp->probe_timer.prev != NULL;
  1091.         break;    
  1092.     default:
  1093.         printk(timer_bug_msg);
  1094.     };
  1095.     return 0;
  1096. }
  1097.  
  1098.  
  1099. #endif    /* _TCP_H */
  1100.